// -----------------------------------------------------------------------
// <copyright file="AdministrativeUnit.cs" company="VDC-IT" author="LTDUC">
//      Copyright (c) VDC-IT. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

namespace VDC.VONE.ENTITIES
{
    using System;
    using System.Collections.Generic;
    using System.Data.SqlClient;
    using AdCom.Utility;
    using VDC.COMMON;

    /// <summary>
    /// Class AdministrativeUnit
    /// </summary>
    public class AdministrativeUnit
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="AdministrativeUnit" /> class
        /// </summary>
        public AdministrativeUnit()
        {
            this.AdministrativeUnitsId = 0;
            this.Code = string.Empty;
            this.Name = string.Empty;
            this.Parent = 0;
            this.Order = 0;
        }

        /// <summary>
        /// Gets or sets AdministrativeUnitsId
        /// </summary>
        public int AdministrativeUnitsId { get; set; }

        /// <summary>
        /// Gets or sets Code
        /// </summary>
        public string Code { get; set; }

        /// <summary>
        /// Gets or sets Name
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets Parent
        /// </summary>
        public int Parent { get; set; }

        /// <summary>
        /// Gets or sets Order
        /// </summary>
        public int Order { get; set; }

        /// <summary>
        /// Gets Users
        /// </summary>
        public IList<User> Users
        {
            get
            {
                try
                {
                    IList<User> lstUser = new List<User>();
                    var reader = SqlDataHelper.ExecuteReader(string.Format(Constants.StorepProcedure.VOneUsersGetByAdministrativeUnitsId, this.AdministrativeUnitsId));
                    while (reader.Read())
                    {
                        User user = new User();
                        if (!reader.IsDBNull(0))
                        {
                            user.UserId = reader.GetInt32(0);
                        }

                        if (!reader.IsDBNull(1))
                        {
                            user.AdministrativeUnitsId = reader.GetInt32(1);
                        }

                        if (!reader.IsDBNull(2))
                        {
                            user.UserName = reader.GetString(2);
                        }

                        if (!reader.IsDBNull(3))
                        {
                            user.FullName = reader.GetString(3);
                        }

                        if (!reader.IsDBNull(4))
                        {
                            user.Sex = reader.GetBoolean(4);
                        }

                        if (!reader.IsDBNull(5))
                        {
                            user.BirthDate = reader.GetDateTime(5);
                        }

                        if (!reader.IsDBNull(6))
                        {
                            user.Email = reader.GetString(6);
                        }

                        if (!reader.IsDBNull(7))
                        {
                            user.Sms = reader.GetString(7);
                        }

                        if (!reader.IsDBNull(8))
                        {
                            user.Phone = reader.GetString(8);
                        }

                        if (!reader.IsDBNull(9))
                        {
                            user.Address = reader.GetString(9);
                        }

                        if (!reader.IsDBNull(10))
                        {
                            user.CreateDate = reader.GetDateTime(10);
                        }

                        if (!reader.IsDBNull(11))
                        {
                            user.Send = reader.GetString(11);
                        }

                        lstUser.Add(user);
                    }

                    reader.Close();
                    reader.Dispose();
                    return lstUser;
                }
                catch (SqlException ex)
                {
                    throw new Exception(ex.ToString());
                }
            }
        }
    }
}
